package sax.utils;

import sax.representation.PAA;
import sax.representation.TimeSeries;

public class PAACreator {

	public static PAA create(TimeSeries timeSeries, int numberOfElements){
		double[] paaArray = new double[numberOfElements];
		
		for(int y=1; y <= numberOfElements; y++){
			Object[] timeSeriesArray = timeSeries.getTimeSeriesArray();
			int ratio = (timeSeriesArray.length/numberOfElements);
			int xMax = ratio*y;
			double sum = 0;
			for(int x=(ratio*(y-1))+1; x<=xMax; x++)
				sum += (Double)timeSeriesArray[x-1];
			
			paaArray[y-1] = ((double)numberOfElements/(double)timeSeriesArray.length)*sum;
		}
		
		PAA paa = new PAA();
		paa.setElements(paaArray);
		return paa;
	}
}
